package com.tom;

public class Member
{
	String id;
	String nickname;
	String password;
	String email;
	
	String commit;
	
	String idMessage;
	String passwordMessage;
	String commitMessage;
	String emailMessage;
	
	boolean validateFlag;
	
 
	public Member()
	{
		setId("");
		setNickname("");
		setPassword("");
		setEmail("");
		setCommit("");
		
		setIdMessage("");
		setPasswordMessage("");
		setCommitMessage("");
		setEmailMessage("");
		setValidateFlag(false);
	}
	
	public Member(String id, String nickname, String password, String email, String commit) 
	{
		super();
		this.id = id;
		this.nickname = nickname;
		this.password = password;
		this.email = email;
		
	    this.commit = commit;
	    
		setIdMessage("");
		setPasswordMessage("");
		setCommitMessage("");
		setEmailMessage("");
		setValidateFlag(false);
	}
	
	
	
	public boolean validate()
	{
		validateFlag = true;
		
		if(id.length() < 4 || id.length() > 20)
		{
			validateFlag = false;
			setIdMessage("帳號長度不符合 !");
		}
		
		if(password.length() < 4 || password.length() > 20)
		{
			validateFlag = false;
			setPasswordMessage("密碼長度不符合 !");
		}
		
		/*
		if(!password.equals(commit))
		{
			validateFlag=false;
			setCommiitMessage("密碼不符合!");
		}
		*/
		
		int passwordValue;
		int commitValue;
		if(password.length() > 0 && commit.length() > 0)
		{
			passwordValue = Integer.parseInt(password);
			commitValue = Integer.parseInt(commit);
			
			if(passwordValue > 0 && commitValue > 0)
			{
				if(passwordValue != commitValue)
				{
					validateFlag = false;
					setCommitMessage("密碼確認不符合 !");
				}
			}
			else
			{
				validateFlag = false;
				setCommitMessage("密碼確認不符合 !");
			}
		}
		else
		{
			validateFlag = false;
			setCommitMessage("密碼確認不符合 !");
		}

		
		if(email.indexOf("@") == -1)
		{
			validateFlag = false;
			setEmailMessage("email 格式不符合 !");
		}
		
		return validateFlag;
		
	}	


	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getNickname() {
		return nickname;
	}
	public void setNickname(String nickname) {
		this.nickname = nickname;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getCommit() {
		return commit;
	}
	public void setCommit(String commit) {
		this.commit = commit;
	}

	public String getIdMessage() {
		return idMessage;
	}
	public void setIdMessage(String idMessage) {
		this.idMessage = idMessage;
	}
	public String getPasswordMessage() {
		return passwordMessage;
	}
	public void setPasswordMessage(String passwordMessage) {
		this.passwordMessage = passwordMessage;
	}
	public String getCommitMessage() {
		return commitMessage;
	}
	public void setCommitMessage(String commitMessage) {
		this.commitMessage = commitMessage;
	}
	public String getEmailMessage() {
		return emailMessage;
	}
	public void setEmailMessage(String emailMessage) {
		this.emailMessage = emailMessage;
	}

	public boolean isValidateFlag() {
		return validateFlag;
	}

	public void setValidateFlag(boolean validateFlag) {
		this.validateFlag = validateFlag;
	}
	
}
